package net.zjitc.dao.impl;

import net.zjitc.dao.AdminDao;
import net.zjitc.domain.AdminUser;
import net.zjitc.utils.C3P0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/10/25 11:14
 * 4
 */
public class AdminDaoImpl implements AdminDao{

    @Override
    public AdminUser sqlLogin(String username,String password) throws SQLException {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        String sql = "select * from adminuser where username = ? and password = ?";
        AdminUser user = null;
        user = (AdminUser) runner.query(sql,new BeanHandler(AdminUser.class),new Object[]{username,password});
        return user;
    }

    @Override
    public AdminUser sqlregister(String username) throws SQLException {
        QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
        String sql = "select * from adminuser where username = ?";
        AdminUser user = null;
        user = (AdminUser) runner.query(sql,new BeanHandler(AdminUser.class),new Object[]{username});
        return user;
    }


}
